package cn.source.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.source.service.IArtStartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.domain.ArtStart;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 收藏文章Controller
 *
 * @author sourcebyte.vip
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/system/start")
public class ArtStartController extends BaseController
{
    @Autowired
    private IArtStartService artStartService;

    /**
     * 查询收藏文章列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArtStart artStart)
    {
        startPage();
        List<ArtStart> list = artStartService.selectArtStartList(artStart);
        return getDataTable(list);
    }

    /**
     * 获取收藏文章详细信息
     */
    @GetMapping(value = "/{id}/{userId}")
    public AjaxResult getInfo(@PathVariable("id") Long id,@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(artStartService.selectArtStartById(id,userId));
    }

    /**
     * 新增收藏文章
     */
    @Log(title = "收藏文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArtStart artStart)

    {
        return toAjax(artStartService.insertArtStart(artStart));
    }

    /**
     * 修改收藏文章
     */
    @Log(title = "收藏文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArtStart artStart)
    {
        return toAjax(artStartService.updateArtStart(artStart));
    }

    /**
     * 删除收藏文章
     */
    @Log(title = "收藏文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(artStartService.deleteArtStartByIds(ids));
    }

    /**
     * 导出收藏文章列表
     */
    @Log(title = "收藏文章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArtStart artStart)
    {
        List<ArtStart> list = artStartService.selectArtStartList(artStart);
        ExcelUtil<ArtStart> util = new ExcelUtil<ArtStart>(ArtStart.class);
        util.exportExcel(response, list, "收藏文章数据");
    }
}
